package edu.sctu.jsoup.service;

import edu.sctu.jsoup.entity.TangschoolEntity;
import edu.sctu.jsoup.entity.TourEntity;
import edu.sctu.jsoup.repo.TangschoolRepo;
import edu.sctu.jsoup.repo.TourRepo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.sql.Blob;
import java.util.List;

@Service
public class TangshoolService {

    @Autowired
    private TourRepo tourRepo;

    @Autowired
    private TangschoolRepo tangschoolRepo;

    public void run(){

//        List<TourEntity> tourEntities = tourRepo.findAll();
//        for (TourEntity entity : tourEntities){
//            System.out.println(entity.getHtml_url());
//        }

        String url = "http://www.tanghu.net";
        try {
            Document document = Jsoup.connect(url).get();

            TangschoolEntity tang = new TangschoolEntity();
            tang.setData(System.currentTimeMillis());
            tang.setHtml(document.html());
            tang.setUrl(url);

            tangschoolRepo.save(tang);
            } catch (IOException e1) {
            e1.printStackTrace();
        }


    }

}
